import requests
from pathlib import Path

class DownloadFile:
    def __init__(self):
        self.url = ''

    def download_mp3(self, url, filename):  
        """  
        眵灃趶URL朋MP3薛佾泫?馻囡縼趶薛證宙  
        
        緙:  
        url (str): MP3薛URL逝宙  
        filename (str): ?馻薛證侈證佾?"song.mp3"佩宙  
        """  
        # 翱GET??  
        response = requests.get(url, stream=True)  
        
        # ????孍  
        response.raise_for_status()  
        
        # 牪'with'樗綬襦薛佾???賰  
        with open(filename, 'wb') as file:  
            # 啅罐塥?  
            for chunk in response.iter_content(chunk_size=8192):  
                # ??chunk焂佾蜦  
                if chunk:  
                    file.write(chunk)  

    def createPath(self, folder_path):
        # 恅璃標繚噤  
        folder_path = Path(folder_path)
        
        # 瓚剿恅璃標岆瘁湔婓  
        if not folder_path.exists():  
            # 彆恅璃標祥湔婓ㄛ寀斐膘恅璃標  
            folder_path.mkdir(parents=True, exist_ok=True)

        return folder_path